package top.yueyazhui.vhr.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import top.yueyazhui.vhr.mapper.MenuMapper;
import top.yueyazhui.vhr.model.Hr;
import top.yueyazhui.vhr.model.Menu;
import top.yueyazhui.vhr.model.Role;

import java.util.List;

@Service
@CacheConfig(cacheNames = "yueyazhui")
public class MenuService {

    @Autowired
    MenuMapper menuMapper;

    public List<Menu> getMenusByHrId() {
//        return menuMapper.getMenusByHrUsername(((String) SecurityContextHolder.getContext().getAuthentication().getPrincipal()));
        return menuMapper.getMenusByHrId(((Hr) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId());
    }

    @Cacheable
    public List<Menu> getAllMenusWithRole() {
        return menuMapper.getAllMenusWithRole();
    }

    public List<Menu> getAll() {
        return menuMapper.getAll();
    }
}
